package Filter;

import javax.servlet.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class experiment_5_2_Filter implements Filter {
    private FilterConfig filterConfig;
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        this.filterConfig = filterConfig;
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        String addr = servletRequest.getServerName();
        System.out.println(addr);
        String[] ad = addr.split(".");
        HttpServletResponse httpServletResponse = (HttpServletResponse)servletResponse;
//        ad[0] == "219" && ad[1] == "218"
        if (!(addr.equals("localhost"))){
            filterChain.doFilter(servletRequest,servletResponse);
        }
        else
            httpServletResponse.sendRedirect("/myfirst_web/experiment_5_2.jsp");

    }

    @Override
    public void destroy() {
        this.filterConfig = null;
    }
}
